package com.xhh.preenroll.listener;

import com.xhh.common.aliyun.util.SMSUtils;
import com.xhh.common.constants.InterviewConstants;
import com.xhh.common.constants.PreenrollConstants;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Map;

@Slf4j
@Component
@RequiredArgsConstructor
public class SendMessageListener {

    private static final String SIGNNAME = "GSA"; // 签名
    private static final String TEMPLATECODE = "SMS_471435390"; // 模板

    @RabbitListener(bindings = @QueueBinding(
        value = @Queue(value = PreenrollConstants.QUEUE_NAME, durable = "true"),
        exchange = @Exchange(PreenrollConstants.EXCHANGE_NAME),
        key = PreenrollConstants.SEND_MESSAGE_KEY
    ))
    public void listenSendMsg(Map<String, String> msg){
        // 发送短信通知
        String phone = msg.get("phoneNumbers");
        String stuName = msg.get("stuName");
        String majorName = msg.get("majorName");
        String param = "{\"stuName\":\""+stuName+"\",\"majorName\":\""+majorName+"\"}";
//        String message = msg.get("msg");
        SMSUtils.sendMessage(SIGNNAME, TEMPLATECODE, phone, param);
//        log.info("短信发送成功: {}", message);
    }
}
